<template>
  <div>
    <div class="Logout">
      <Logout>退出</Logout>
    </div>
    <h1>选择课程</h1>
    <el-input style="width: 800px" size="large" v-model="user.sno" placeholder="请输入成员编号" prefix-icon="el-icon-s-custom" maxlength="10" show-word-limit clearable></el-input>
    <el-input style="width: 800px" size="large" v-model="user.cno" placeholder="请输入关系编号" prefix-icon="el-icon-price-tag" maxlength="10" show-word-limit clearable></el-input>
    <el-row>
      <el-button @click="join" type="success" icon="el-icon-check">提交</el-button>
    </el-row>
  </div>
</template>

<script>
import Logout from "./Logout";
export default {
  name: "ChooseRelation",
  components:{Logout},
  created() {
    const _this = this;
    this.$axios.post(`/ChooseRelation`, {...this.user}).then((res) => {
      console.log("1");
      console.log(res.data);
      _this.tableData = res.data;
    })
  },
  methods : {
    search() {
      const _this = this;
      this.$axios.get(`/relation/list?cno=${this.search_cno}`).then((res) => {
        console.log("2");
        console.log(res.data);
        _this.tableData = res.data;
      })
    },
    join() {
      // console.log("3");
      // console.log(row);
      // const cno = row.cno;
      const stuNo = localStorage.getItem("stuno");
      console.log("选课的学生信息：", this.user.sno, this.user.cno)
      this.$axios.post(`/ChooseRelation`, {...this.user}).then((res) => {
        console.log(res);
        if ("选课成功" === res.data.msg) {
          alert("报名成功，请及时缴费");
          this.$router.push({path:'/Pay', query:{
              cno:cno,
              stuNo:stuNo,
            }});
        } else {
          alert(res.data.msg)
        }
      });
    },
    delRelation(row) {
      console.log("5");
      console.log(row);
      const cno = row.cno;
      const _this = this;
      this.$axios.get(`/relation/delete?cno=${cno}`).then((res) => {
        alert("删除成功");
        this.$axios.get(`/relation/list?cno=${_this.search_cno}`).then((res) => {
          console.log(res.data);
          _this.tableData = res.data;
        })
      })
    },
  },
  data() {
    return {
      search_cno : '',
      tableData : '',
      user:{
        sno:'',
        cno:'',
      },
    }
  }
}
</script>

<style scoped>

</style>
